﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;

namespace PeisongWeb.admin
{
    public partial class priceStructureList : adminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (hasPermission("BD", 2))
                {
                    rptBind();
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "index.aspx");
                    return;
                }
            }
        }
        void rptBind()
        {
            StringBuilder where = new StringBuilder();
            where.Append("treelevel=1");
            if (txt_categoryName.Text.Trim() != "")
                where.AppendFormat("and name like '%{0}%'", txt_categoryName.Text.Trim());
            DataSet ds = logic.category.subList(where.ToString(), "categoryId", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            rpt_list.DataSource = ds.Tables[1];
            rpt_list.DataBind();
        }

        protected void rpt_list_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Update")
            {
                int categoryId = Convert.ToInt32(e.CommandArgument);
                hd_cid.Value = categoryId.ToString();
                lbl_categoryName.Text = logic.category.getById(categoryId).Name;
                win_pricestruc.Show();
            }
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            rptBind();
        }
        protected void lbtn_Search_Click(object sender, EventArgs e)
        {
            rptBind();
        }

        protected void btn_Save_Click(object sender, EventArgs e)
        {
            int categoryId = Convert.ToInt32(hd_cid.Value);
            decimal autoAdd = Convert.ToDecimal(txt_autoAdd.Text);
            logic.product.updateAutoAddByCategoryId(categoryId,autoAdd);
            txt_autoAdd.Text = "";
            Library.Script.ClientMsg("价格编辑成功！");
        }
    }
}
